package de.jmda.gen.java.impl;

import static de.jmda.util.StringUtil.sb;
import de.jmda.gen.GeneratorException;
import de.jmda.gen.impl.DefaultGenerator;
import de.jmda.gen.java.ImportStatementGenerator;
import de.jmda.util.StringUtil;

public class DefaultImportStatementGenerator
		extends DefaultGenerator
		implements ImportStatementGenerator
{
	public DefaultImportStatementGenerator(String importStatement)
  {
	  super(importStatement);
  }

	@Override
  public StringBuffer generate() throws GeneratorException
  {
		StringBuffer result = super.generate();
		
		if (false == StringUtil.isBlank(result))
		{
			result = StringUtil.rTrimChars(result, System.lineSeparator());

			String prefix = "import ";
			String suffix = ";";

			if (false == StringUtil.startsWith(result, prefix))
			{
				result = sb(prefix).append(result);
			}

			if (false == StringUtil.endsWith(result, suffix))
			{
				result.append(suffix);
			}
		}
		
		return result;
  }
}